﻿@{
    ViewBag.Title = "角色管理";
    Layout = "~/Views/Shared/_ManagerLayoutPage.cshtml";

    var data = ViewBag.data;

    var core = Newtonsoft.Json.JsonConvert.SerializeObject(ViewData["core"]);

    var role = ViewData["role"] == null ? null : ViewData["role"] as BaseAuthRole.DTO.Role.Role;
}

@section ChildPageCss
    {

    <link href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/vendor/jsTree/style.min.css" rel="stylesheet" />

}

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body">
                <div class="col-md-12">

                    <p style="font-size:15px;font-weight:bold;">编辑角色</p>
                    <div class="form-group">
                        <lable class="col-sm-2 control-lable require">角色名</lable>
                        <div class="col-sm-4">
                            <input id="name" class="form-control" value="@(role==null?"":role.Name)">
                        </div>
                    </div>
                    <div class="form-group">
                        <lable class="col-sm-2 control-lable require">描述</lable>
                        <div class="col-sm-4">
                            <input id="des" class="form-control" value="@(role==null?"":role.Description)">
                        </div>
                    </div>
                    <div class="form-group">
                        <lable class="col-sm-2">权限</lable>
                        <div class="col-sm-8" id="baseContent">

                        </div>
                    </div>
                    <div class="form-group">

                        <div class="col-sm-4 col-sm-offset-2">
                            <button class="btn btn-success" onclick="BasicSubmit(this)" type="button">保存</button>
                            <button class="btn  btn-outline-secondary" onclick="history.go(-1)" type="button">返回</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@section ChildPageScript{


    <script src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/vendor/jsTree/jstree.min.js"></script>

    <script>
      
        $(document).ready(function ()
        {
            Init();
        });

        function Init()
        {
            $.ajax({

                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + "@Url.Action("GetRoleInfo", "RoleManager")",
                dataType: "json",
                data: { "id": "@Context.Request.Query["id"]" },
                type: "get",
                success: function (data)
                {
                    if (!data.IsError) {
                        $("#baseContent").jstree({
                            "checkbox":
                            {
                                "keep_selected_style": false
                            },
                            "core":{
                            "data":data.Result.data
                            }, 
                            "plugins": ["checkbox"],
                            
                        });
                    }
                }
            })
        }


        function BasicSubmit(obj)
        { 
           

            var name = $("#name").val();

            var des = $("#des").val();

            var data = $("#baseContent").jstree("get_checked").join(",");


            if (name == "")
            {
                Notic("warning","名称不能为空");
                return;
            }

            if (des == "")
            {
                Notic("warning", "描述不能为空");
                return;
            }

            console.log(data);

           

            $(obj).attr("disabled", "disabled");
             $.ajax({

                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + "@Url.Action("EditRoleDo", "RoleManager")",
                dataType: "json",
                 data: { "name": name, "des": des, "data": data,"id": "@Context.Request.Query["id"]"},
                type: "post",
                success: function (data) {
                    console.log(data);

                    if (data.IsError) {

                        Notic('error',data.Message);
                    }
                    else
                    {
                        Notic('info', "操作成功");


                    }


                },
                fail: function (data) {


                },
                complete: function (data) {


                    $("#loading").hide();

                    $(obj).removeAttr("disabled");

                }
            });

        }


    </script>

}
